define(function(require,exports,module){

	//检测类
	//var Auth = require('qd-auth-1.0');


	getLotteryList();	
	
	require.async("awardRotate.js",function(){
		require.async(['/plugins/layer-v1.8.4/skin/layer.css','layer_nQ'],function(){

			var rotateTimeOut = function (){
				$('#rotate').rotate({
					angle:0,
					animateTo:2160,
					duration:8000,
					callback:function (){
						tipsBox('网络超时，请检查您的网络设置！');
					}
				});
			};
			var bRotate = false;

			var rotateFn = function (angles, txt){
				bRotate = !bRotate;
				$('#rotate').stopRotate();
				$('#rotate').rotate({
					angle:0,
					animateTo:angles+1800,
					duration:8000,
					callback:function (){
						tipsBox(txt);
						bRotate = !bRotate;
					}
				})
			};

			$('.pointer').live("click",function(){
				$("#pointer").removeClass("pointer");
				$.ajax({
				      type:"get",
				      cache:false,
				      url:'/member/doSignLottery.html?randomTime=' + (new Date()).getTime(),
				      dataType:"json",
				      success:function(data){
							//单点登录检测
						  //if(Auth.checkLogin(arguments[0]) == false) {return ;}


				    	  if(!data.msg){
				    		  if(bRotate) return;
                              rotateFn(data.result.pos, data.result.message);
                              /*
					    	  switch (data.result.type) {
								case 0:
									rotateFn(0, 330, data.result.message);
									break;
								case 1:
									rotateFn(1, 26, '恭喜您！您获得了1000元现金！');
									break;
								case 2:
									rotateFn(2, 80, '恭喜您！您获得了50元现金!');
									break;
								case -1:
									rotateFn(-1, 130, '未中奖');
									break;
								case 3:
									rotateFn(3, 180, '恭喜您！您获得了5元现金！');
									break;
								case 4:
									rotateFn(4, 230, '恭喜您！您获得了500个积分！');
									break;
								case 5:
									rotateFn(5, 280, '恭喜您！您获得了100个积分！');
									break;
							}
					    	*/
				    	  }else{
				    		  tipsBox(data.msg);
				    	  }
				      }
			    });
			});
			//定义积分抽奖公用弹出样式
			var tipsBox = function(txt){
				//构造确认框DOM
				$.layer({
					type: 1,
					closeBtn: false,
	                title: false,
					area: ['384', '188px'],
					border: [0],
					fadeIn: 300,
					time:2000000000,
					page: {
					    html: '<div class="lotteryTipsWrap w384"><div class="lotteryTipsTitle"><a href="javascript:;" class="tipCloseBtn">X</a></div><p class="tipsTxt">'+txt+'</p><div class="tipsBtnBar"><a href="/member/main.html" class="tipCloseBtn">确定</a></div></div>'
					},
    			    close: function(index){
    			    	getLotteryList();
    			    }
				})
				$(".tipCloseBtn").click(function(){
					getLotteryList();
					layer.closeAll();
				});
			}
		})
	})

	
	//获奖名单滚动效果
	function slideTop(obj,slideTimer,showTimer){
        var box = $(obj);
        var Timer;
        box.hover(function(){
            clearInterval(Timer)
        },function(){
            Timer = setInterval(function(){
                scrollNew(box,showTimer);
            },slideTimer)
        }).trigger("mouseleave");
        function scrollNew(obj,showTimer){
            var scrollBox = obj.find("ul:first");
            var liHeight = scrollBox.find("li:first").height();
            scrollBox.animate({"marginTop":-liHeight+"px"},showTimer,function(){
                scrollBox.css("marginTop",0).find("li:first").appendTo(scrollBox);
            })
        }
    }
	
	//获奖名单
	function getLotteryList(){
		var str="";
		$.ajax({
		      type:"get",
		      cache:false,
		      url:'/member/signLotteryList.html?randomTime=' + (new Date()).getTime(),
		      dataType:"json",
		      success:function(data){
		    	  var prize = data.data;
					var len = prize.length;
					for( var i = 0 ; i<len ; i++){
						if(prize[i].type ==1){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;个积分</li>';
						}else if(prize[i].type ==2){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;元现金</li>';
						}else if(prize[i].type ==3){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;%加息券</li>';
						}else if(prize[i].type ==4){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;次抽奖机会</li>';
						}else if(prize[i].type ==5){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;张电影票</li>';
						}else if(prize[i].type ==6){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;元现金红包</li>';
						}else if(prize[i].type ==7){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;元体验券</li>';
						}else if(prize[i].type ==9){
							str+='<li><span class="name">'+prize[i].userName+'</span><span>抽中了</span>'+prize[i].value+'&nbsp;元投资红包</li>';
						}
					}
					$(".winnersList ul").html(str);
					$("#pointer").addClass("pointer");
		      }
	    });
	}
  
	slideTop(".winnersList",2000,1000);

});